<template>
    <el-form :model="login" :rules="loginrules" ref="refs" label-width="100px" class="demo-ruleForm">
        <el-form-item label="名称" prop="name">
            <el-input v-model="login.name"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="pass">
            <el-input type="password" v-model="login.pass" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="Login()">登录</el-button>
            <el-button @click="resetForm('login')">重置</el-button>
        </el-form-item>
    </el-form>
</template>

<script>
    import { ref, reactive } from 'vue'
    import { useRouter } from 'vue-router';
    export default {
        name: 'App',
        setup() {
            let router = useRouter();
            let refs = ref("");
            let login = reactive({
                name: "",
                pass: '',
            })
            let loginrules = {
                name: [
                    {
                        required: true,
                        message: "请输入名称",
                        trigger: "blur"
                    },
                ],
                pass: [
                    {
                        required: true,
                        message: "请输入密码",
                        trigger: "blur"
                    },
                ],
            }
            function Login() {
                refs.value.validate((valid) => {
                    if (valid) {
                        router.push('/Main');
                    }
                })
            }
            return {
                login,
                loginrules,
                refs,
                Login,
            }
        }
    }
</script>